// import { clipboard } from '@ve/utils/clipboard'
// import { jsonToTable } from '@ve/utils/jsonToTable'
import trim from 'lodash/trim'
import isEmpty from 'lodash/isEmpty'
// import { Toast } from 'vant'

//必须带done回调 执行完成调用
export default function pdaGetCardData({ vm, action, additionalData, done }) {
  let { useInpData, getDataKey } = action.extension
  console.log('获取卡片值--------------------', useInpData, getDataKey)
  // let _data = {}
  let _resData = {}
  let _postData = {}
  if (useInpData.value) {
    if (isEmpty(additionalData)) {
      let moduleId = vm.info._id
      _resData = vm.vuiComponents[moduleId].self.clickObj
      if (vm.vuiComponents[moduleId]) {
        if (!isEmpty(getDataKey?.value)) {
          const getDataKeyList = getDataKey.value.split(',')
          console.log('获取卡片值', getDataKeyList, getDataKey.value)
          getDataKeyList.map((item) => {
            item = trim(item)
            // 有注入数据 key 则用注入数据 key, 没有则用获取数据 key
            _postData[item] = _resData[item]
          })
        } else {
          _postData = _resData
        }
        console.log('选中的卡片值', _postData)
      } else {
        console.log('暂未找到该组件')
      }
    }
  }
  // 存储动作数据
  vm.$store.dispatch('actionDatas/setActionsData', {
    moduleId: vm.info._id,
    actionId: action._id,
    actionData: _postData,
  })
  done(null, _postData)
}
